package com.bw.base.view

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import java.lang.reflect.ParameterizedType

abstract class BaseActivity<VDB:ViewDataBinding> :AppCompatActivity() {

    private val type by lazy { (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments }

     val binding: VDB by lazy {
        //拿到第一个泛型的class
        val clazz = type[0] as Class<VDB>
        //通过反射,拿到activity中inflate的方法
        val method = clazz.getMethod("inflate", LayoutInflater::class.java)
        //通过反射放大的调用,自定绑定第一个参数的值(布局)
        method.invoke(null, layoutInflater) as VDB
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(binding.root)

        initView()
        initData()


    }

    abstract fun initView()
    abstract fun initData()




}